package com.icinfo.cloud.provider.punish.fastcase.controller;

import cn.hutool.core.util.ObjectUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.peripheralinterface.regulatory.vo.PunishItemVo;
import com.icinfo.cloud.provider.punish.config.service.IConfigFastCaseMattersService;
import com.icinfo.cloud.provider.punish.config.service.IConfigFastProcedureService;
import com.icinfo.cloud.provider.punish.fasecase.dto.FastNoticeDocumentDto;
import com.icinfo.cloud.provider.punish.fastcase.dto.*;
import com.icinfo.cloud.provider.punish.fastcase.service.IFastCaseRegisterService;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastAutoCloseCaseReminderVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseNoticeDocumentVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseRegisterInfoVo;
import com.icinfo.cloud.provider.punish.ucase.caseregister.dto.CaseRegisterDetailQueryDto;
import com.icinfo.cloud.provider.punish.ucase.caseregister.dto.CheckIsFastProcedureDto;
import com.icinfo.cloud.provider.punish.ucase.caseregister.service.ICaseRegisterService;
import com.icinfo.cloud.provider.punish.ucase.caseregister.vo.CaseRegisterSaveVo;
import com.icinfo.framework.common.web.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 简案快办 立案登记阶段 控制器
 *
 * @author cds
 * @date 2022/12/2
 * @since 汇信科技
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/punish/fast/case/register")
public class FastCaseRegisterController {

    private final IFastCaseRegisterService fastCaseRegisterFeignApi;

    @Resource
    private IConfigFastProcedureService configFastProcedureService;
    @Resource
    private ICaseRegisterService caseRegisterService;
    @Resource
    private IConfigFastCaseMattersService configFastCaseMattersService;

    /**
     * 速结告知书生成 并返回前端文书地址
     *
     * @param dto
     * @return
     */
    @PostMapping("/getFastNoticeDocument")
    public Result<FastNoticeDocumentDto> generateFastNoticeDocument(@RequestBody CaseRegisterDetailQueryDto dto){
        FastNoticeDocumentDto result =  fastCaseRegisterFeignApi.generateFastNoticeDocument(dto);
        return Result.success(result);
    }


    /**
     * 校验立案选择的事项是否为配置的事项库中的事项
     * @param dto
     * @return
     */
    @PostMapping("/checkIsFastProcedure")
    public Result<Boolean> checkIsFastProcedure(@RequestBody @Validated CheckIsFastProcedureDto dto){
        int count = configFastCaseMattersService.getFastProcedureNumByListCodeAndOrgCode(dto.getOrgCode(), dto.getListCode());
        return Result.success(count > 0 ? Boolean.TRUE : Boolean.FALSE);
    }

    /**
     * 【AJ-V1.1.1】描述： 速结程序转普通程序
     *
     * @author: zhengqiang
     * @date: 2023/3/8
     * @param: caseId
     * @return {@link Result}
     **/
    @GetMapping("/changeToNormalProcedure")
    public Result changeToNormalProcedure(@RequestParam("caseId") String caseId) {
        return fastCaseRegisterFeignApi.changeToNormalProcedure(caseId);
    }

    /**
     * 【V1.11.4】描述： 修改简案快办立案(处罚告知)相关文书
     *
     * @author: zhengqiang
     * @date: 2023/4/20
     * @param: modifyOfRegisterDto
     * @return {@link Result}
     **/
    @PostMapping("/modifyFastCaseRegisterDocuments")
    public Result modifyFastCaseRegisterDocuments(@RequestBody @Validated FastCaseDocumentModifyOfRegisterDto modifyOfRegisterDto) {
        return fastCaseRegisterFeignApi.modifyFastCaseRegisterDocuments(modifyOfRegisterDto);
    }

    /**
     * 【V1.11.4】描述： 简案快办待提交文书编辑通用方法
     *
     * @author: zhengqiang
     * @date: 2023/4/28
     * @param: modifyDto
     * @return {@link Result}
     **/
    @PostMapping("/modifyFastCaseDocumentRecord")
    public Result modifyFastCaseDocumentRecord(@RequestBody @Validated FastCaseDocumentRecordModifyDto modifyDto) {
        fastCaseRegisterFeignApi.modifyFastCaseDocumentRecord(modifyDto);
        return Result.success(Constant.STRING_SUCCESS_EN);
    }

    /**
     * 【V1.11.4】描述： 修改移动端简案快办立案(处罚告知)相关文书
     *
     * @author: zhengqiang
     * @date: 2023/5/4
     * @param: modifyOfRegisterDto
     * @return {@link Result}
     **/
    @PostMapping("/modifyAppFastCaseRegisterDocuments")
    public Result modifyAppFastCaseRegisterDocuments(@RequestBody @Validated AppFastCaseDocumentModifyOfRegisterDto modifyOfRegisterDto) {
        return fastCaseRegisterFeignApi.modifyAppFastCaseRegisterDocuments(modifyOfRegisterDto);
    }

    /**
     * 【V1.12.1】描述：简案快办立案登记
     *
     * @author: zhengqiang
     * @date: 2023/8/16
     * @param: saveDto
     * @return {@link Result< CaseRegisterSaveVo>}
     **/
    @PostMapping(value = "/saveFastCaseRegister")
    public Result<CaseRegisterSaveVo> saveFastCaseRegister(@RequestBody @Validated FastCaseRegisterSaveDto saveDto) {
        CaseRegisterSaveVo caseRegisterSaveVo = caseRegisterService.saveFastCaseRegister(saveDto);
        if (ObjectUtil.isNotEmpty(caseRegisterSaveVo)) {
            return Result.success(caseRegisterSaveVo);
        }
        return Result.error("立案失败！");
    }

    /**
     * 【V1.12.1】描述： 查询简案快办暂存数据
     *
     * @author: zhengqiang
     * @date: 2023/8/17
     * @param: queryDto
     * @return {@link Result< FastCaseRegisterInfoVo>}
     **/
    @PostMapping(value = "/getFastCaseRegisterInfo")
    public Result<FastCaseRegisterInfoVo> getFastCaseRegisterInfo(@RequestBody @Validated FastCaseRegisterInfoQueryDto queryDto) {
        FastCaseRegisterInfoVo fastCaseRegisterInfo = caseRegisterService.getFastCaseRegisterInfo(queryDto);
        return Result.success(fastCaseRegisterInfo);
    }

    /**
     * 【V1.12.1】描述： 获取简案快办告知书
     *
     * @author: zhengqiang
     * @date: 2023/8/17
     * @param: dto
     * @return {@link Result< FastCaseNoticeDocumentVo>}
     **/
    @PostMapping("/getFastCaseNoticeDocument")
    public Result<FastCaseNoticeDocumentVo> getFastCaseNoticeDocument(@RequestBody @Validated FastCaseRegisterInfoQueryDto dto) {
        FastCaseNoticeDocumentVo fastCaseNoticeDocument = fastCaseRegisterFeignApi.createFastCaseNoticeDocument(dto);
        return Result.success(fastCaseNoticeDocument);
    }

    /**
     * 【V1.12.1】描述： 查询简案快办提示
     *
     * @author: zhengqiang
     * @date: 2023/8/17
     * @param: dto
     * @return {@link Result< String>}
     **/
    @PostMapping("/getFastTipsByListCodeAndOrgCode")
    public Result<String> getFastTipsByListCodeAndOrgCode(@RequestBody @Validated FastTipsQueryDto dto) {
        String fastTips = configFastCaseMattersService.getFastTipsByListCodeAndOrgCode(dto.getOrgCode(), dto.getListCode());
        return Result.success(Constant.STRING_SUCCESS_EN, fastTips);
    }

    /**
     * 【V1.12.1】描述： 快办告知步骤操作(上一步,下一步)
     *
     * @author: zhengqiang
     * @date: 2023/8/18
     * @param: dto
     * @return {@link Result}
     **/
    @PostMapping("/saveFastInformOperateStep")
    public Result<String> saveFastInformOperateStep(@RequestBody @Validated FastCaseRegisterOperateDto dto) {
        int count = fastCaseRegisterFeignApi.saveFastInformOperateStep(dto);
        return count > 0 ? Result.success(Constant.STRING_OPERATE_SUCCESS) : Result.error(Constant.STRING_OPERATE_FAIL);
    }

    /**
     * 【V1.12.1】描述： 获取简案快办处罚事项
     *
     * @author: zhengqiang
     * @date: 2023/8/23
     * @param: orgCode
     * @return {@link Result< List< Map>>}
     **/
    @GetMapping("/getFastAuditPubishTreeByOrgCode")
    public Result<List<PunishItemVo>> getFastAuditPubishTreeByOrgCode(@RequestParam("orgCode") String orgCode) {
        List<PunishItemVo> fastAuditPubishTreeByOrgCode = fastCaseRegisterFeignApi.getFastAuditPubishTreeByOrgCode(orgCode);
        return Result.success(Constant.STRING_SUCCESS_EN, fastAuditPubishTreeByOrgCode);
    }

    /**
     * 【V1.12.1】描述： 获取自动结案提醒
     *
     * @author: zhengqiang
     * @date: 2023/8/24
     * @param: caseId
     * @return {@link Result< FastAutoCloseCaseReminderVo>}
     **/
    @GetMapping("/getAutoCloseCaseReminder")
    public Result<FastAutoCloseCaseReminderVo> getAutoCloseCaseReminder(@RequestParam("caseId") String caseId) {
        FastAutoCloseCaseReminderVo autoCloseCaseReminder = fastCaseRegisterFeignApi.getAutoCloseCaseReminder(caseId);
        return Result.success(autoCloseCaseReminder);
    }

}
